/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

// TODO re-enable audit
// $codepro.audit.disable
package edu.gatech.teama.doctorsoffice.client.presenter;

import javax.swing.JOptionPane;

import edu.gatech.teama.doctorsoffice.client.view.DoctorNurseMainPanel;
import edu.gatech.teama.doctorsoffice.client.view.MainWindow;
import edu.gatech.teama.doctorsoffice.client.view.PatientMainPanel;
import edu.gatech.teama.doctorsoffice.client.view.SystemAdminMainPanel;
import edu.gatech.teama.doctorsoffice.model.Doctor;
import edu.gatech.teama.doctorsoffice.model.Nurse;
import edu.gatech.teama.doctorsoffice.model.Patient;
import edu.gatech.teama.doctorsoffice.model.SystemAdmin;
import edu.gatech.teama.doctorsoffice.net.LoginResult;

/**
 * LoginPresenter.java
 * @author - unknown
 * @version 1.0
 */
public class LoginPresenter {

	//private LoginPanel myView;
	
	/**
	 * login presenter constructor
	 */
	public LoginPresenter () {
		//myView = view;
		//myView.addComponentListener(this);
		/*Server srv = new Server(4123, "test.dat");
		ExecutorService pool = Executors.newSingleThreadExecutor();
		pool.execute(srv);*/
	}
	
	/**
	 * login
	 * @param username
	 * @param password
	 */
	public void login(String username, String password) {
		ServerConnection srv = ServerConnection.getInstance();
		
		if (srv.login(username, password) != LoginResult.VALID)
			JOptionPane.showMessageDialog(null, "Bad Password");
		System.out.println(srv.getLoggedInUser());
		if (srv.getLoggedInUser() instanceof SystemAdmin) {
			MainWindow.setPanel(new SystemAdminMainPanel());
		} else if (srv.getLoggedInUser() instanceof Patient) {
			MainWindow.setPanel(new PatientMainPanel());
		} else if (srv.getLoggedInUser() instanceof Doctor
				|| srv.getLoggedInUser() instanceof Nurse) {
			MainWindow.setPanel(new DoctorNurseMainPanel());
		}
	}

}
